﻿/** \file
* \par Subversion URL:
* \$URL: http://planar-rendering.googlecode.com/svn/trunk/frontend/src/Orth.cs $
* \version \$Rev: 74 $
* \date    \$Date: 2009-04-20 01:12:01 +0000 (Mon, 20 Apr 2009) $
*/

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Frontend
{
	/// <summary>
	/// The orthagonal renders form.
	/// </summary>
	public partial class Orth : Form
	{
		/// <summary>
		/// The images, three dimensions by three render styles.
		/// </summary>
		Bitmap[,] images = new Bitmap[3,3];

		/// <summary>
		/// The constructor. Initializes the images.
		/// </summary>
		public Orth()
		{
			InitializeComponent();

			OrthTarget targ = Program.targetOrth;
			Generator gen = Program.generator;

			for (int d = 0; d < 3; d++)
			{
				int d1 = (d + 1) % 3;
				int d2 = (d + 2) % 3;

				Rectangle whole = new Rectangle();

				for (int m = 0; m < 3; m++)
				{
					images[d, m] = new Bitmap(
						gen.spatialranges[d2].res,
						gen.spatialranges[d1].res,
						PixelFormat.Format32bppRgb);
					if (m == 0)
						whole = new Rectangle(Point.Empty, images[d,0].Size);
					BitmapData block = images[d, m].LockBits(
						whole,
						ImageLockMode.WriteOnly,
						PixelFormat.Format32bppRgb);
					int size = block.Height * block.Stride / sizeof(int);

					Marshal.Copy(targ.images[d][m], 0, block.Scan0, size);
					images[d, m].UnlockBits(block);
				}
			}
		}

		/// <summary>
		/// Called when the form is loaded. Sets all nine images.
		/// </summary>
		/// <param name="sender">The event sender.</param>
		/// <param name="e">The event arguments.</param>
		void Orth_Load(object sender, EventArgs e)
		{
			imageZPos.Image   = images[0,0];
			imageYPos.Image   = images[1,0];
			imageXPos.Image   = images[2,0];
			imageZNeg.Image   = images[0,1];
			imageYNeg.Image   = images[1,1];
			imageXNeg.Image   = images[2,1];
			imageZAlpha.Image = images[0,2];
			imageYAlpha.Image = images[1,2];
			imageXAlpha.Image = images[2,2];
		}
	}
}
